package com.jd.fruit.model.admin.order;

import java.io.IOException;

import com.jd.fruit.common.annotation.Table;
import com.jd.fruit.common.model.BaseModel;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

@SuppressWarnings("serial")
@Table("t_user")
public class OrderUser extends BaseModel<OrderUser>{

	public static final OrderUser dao = new OrderUser();
		
	/**
	 * 后台用户登陆
	 * @param loginName
	 * @param password
	 * @return
	 */
	public OrderUser checkLogin(String loginName, String password) {
		   String sql="SELECT * FROM `t_user`  t WHERE t.iphone_no =? AND t.iphone_password=?";
		   return this.findFirst(sql, loginName,password);
		}
	

	/**
	 * 检查手机号
	 * @param user
	 */
	public boolean  checkTelphone(String telphone){
		boolean isExist = false; 
		try {
		    Record resut=Db.findFirst("select id from t_user where iphone_no = ?", telphone);
			if(resut!=null&&!resut.equals("")){
				isExist=true;
				
			}
	
		} catch (Exception e) {
			throw new RuntimeException("查询手机号失败！", e);
		}
		return isExist;
	}
	/**
	 * 保存用户
	 * @param user
	 */
	public void register(OrderUser user){
		try {
			user.save();
		} catch (Exception e) {
			throw new RuntimeException("用户注册失败！", e);
		}
	}
	/**
	 * 
	 */
	public Page<OrderUser> list(int pageNumber,int pageSize){ 
		whereParams.clear();
		StringBuffer whereSql=new StringBuffer("FROM `t_user` o  where 1=1 ");
		if(StrKit.notBlank(this.getStr("iphone_no"))){
			whereSql.append(" and o.iphone_no like '%").append(getStr("iphone_no")+"%").append("'");
			whereParams.add(getStr("iphone_no"));
		}
		return this.paginate(pageNumber, pageSize,"SELECT * " ,whereSql.toString(),whereParams.toArray());
	}
	/**
	 * 开通店铺资格
	 * @param user
	 */
	public void openUpdate(String id){

		Db.update("update  t_user t set t.identity='3'   where  t.id=?",id);
	}
	/**
	 * 取消店铺资格
	 * @param user
	 */
	public void closeUpdate(String id){
		Db.update("update  t_user t set t.identity='2'   where  t.id=?",id);
	}
	@Override
	public void initWhere() {
		// TODO Auto-generated method stub
		
	}

}
